package de.jmda.mview.proc;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.annotation.processing.Processor;

import de.jmda.gui.swing.mvc.ControllerSupportEnabledProcessor;
import de.jmda.mproc.LaunchConfiguration;
import de.jmda.mproc.Launcher;
import de.jmda.util.fileset.FileSet;
import de.jmda.util.fileset.FileSet.RuleSetUpdateMode;
import de.jmda.util.fileset.FileSetJavaFilesOnly;

public class GenerateControllerSupport
{
	private LaunchConfiguration launchConfiguration;
	
	public GenerateControllerSupport(
      LaunchConfiguration launchConfiguration)
  {
	  super();
	  this.launchConfiguration = launchConfiguration;
  }

	public void launch()
	{
		Processor processor = new ControllerSupportEnabledProcessor();

		try
    {
	    assertTrue(
	    		"unexpected return value for launch of " +
	    		processor.getClass().getName(),
	    		Launcher.launch(launchConfiguration));
    }
    catch (IOException e)
    {
    	fail(
    			"failure launching annotation processor [" +
    			processor.getClass().getName() + "]\n" + e);
    }
	}

	public static void main(String[] args)
  {
  	FileSetJavaFilesOnly fileSet = new FileSetJavaFilesOnly();

  	fileSet.includeDirectoryRecursive(
  			new File("./src/main/java"), RuleSetUpdateMode.ADD_RULE);
  	
  	List<File> fileList = new LinkedList<File>();
  	
  	fileList.addAll(fileSet.calculateFileSet());

  	LaunchConfiguration launchConfiguration = new LaunchConfiguration();

		launchConfiguration.files.addAll(fileList);
		launchConfiguration.processors.add(new ControllerSupportEnabledProcessor());
		
	  GenerateControllerSupport launcher =
	  		new GenerateControllerSupport(launchConfiguration);
	  launcher.launch();
  }
}